<?php
if(My::arr2var($params,'name')=='')  return '控件的name属性不能为空!';
//解释params参数
$params = self::dealParams($params);
//data解码
if(!is_array($params['data']))
	$params['data'] = My::decodeJson($params['data']);
//限制最大行数
$max_num = My::arr2var($params,'formParams.max_num');
//额外参数(如:id=7&table=datas)
$photo_limit = (My::arr2var($params,'photo_limit')!='')?'&'.My::arr2var($params,'photo_limit'):"";
//input框标题3
$input_price_old = !empty($params['formParams']['input_price_old'])?$params['formParams']['input_price_old']:'原价格';
$input_width1 = !empty($params['formParams']['input_width1'])?'width:'.$params['formParams']['input_width1'].'px;':'width:60px;';
$input_maxlength1 = !empty($params['formParams']['input_maxlength1'])?'maxlength="'.$params['formParams']['input_maxlength1'].'"':'';
//input框标题2
$input_price = !empty($params['formParams']['input_price'])?$params['formParams']['input_price']:'优惠价格';
$input_width2 = !empty($params['formParams']['input_width2'])?'width:'.$params['formParams']['input_width2'].'px;':'width:60px;';
$input_maxlength2 = !empty($params['formParams']['input_maxlength2'])?'maxlength="'.$params['formParams']['input_maxlength2'].'"':'';
//input框标题1
$input_model = !empty($params['formParams']['input_model'])?$params['formParams']['input_model']:'商品型号名称';
$input_width3 = !empty($params['formParams']['input_width3'])?'width:'.$params['formParams']['input_width3'].'px;':'width:100px;';
$input_maxlength3 = !empty($params['formParams']['input_maxlength3'])?'maxlength="'.$params['formParams']['input_maxlength3'].'"':'';
//input框标题4
$input_stock = !empty($params['formParams']['input_stock'])?$params['formParams']['input_stock']:'库存';
$input_width3 = !empty($params['formParams']['input_width3'])?'width:'.$params['formParams']['input_width3'].'px;':'width:100px;';
$input_maxlength3 = !empty($params['formParams']['input_maxlength3'])?'maxlength="'.$params['formParams']['input_maxlength3'].'"':'';

//dump($params['data']);
//json
$params['data'] = is_array($params['data'])?array_values($params['data']):array();//重新排序数组//将数组的键值全部替换成数字0开头的数组
$params['data'] = json_encode($params['data']);
$theme = __PUB__.'share';
$html= "<!--array_input S-->
		<div class='{$params['class']}'>
		  <span class='label number_stat' style='position:absolute;margin-top:-3px;margin-left:-3px;'></span>
		  <table class='change_table'>
			<thead>
				<tr class='thead'>
					<th>{$input_model}</th>
					<th>{$input_price}</th>
					<th>{$input_price_old}</th>			
					<th>{$input_stock}</th>			
					<th style='width:65px;'><img src='{$theme}/images/gg_icon1.png' max_num='{$max_num}' class='add_tr' title='鼠标左击:前, 鼠标右击:后'/></th>
				</tr>
			</thead>
			<tbody>
			</tbody>
		  </table>
		</div>
		<script>$(document).ready(function(){ $('.{$params['class']} tbody').sortable({items:\"tr:not('.nodrag')\"}); });</script>
		<script>
		$(function(){
			$('.{$params['class']}').changeTable({data:'{$params['data']}',trHtmlId:'{$params['class']}_tr_html'});
		});
		</script>
		<script id='{$params['class']}_tr_html' type='text/html'>
			<tr lang='<%=num%>'>
				<td class='textal'> <input type='text' name='{$params['name']}[<%=num%>][model]' {$input_maxlength3} style='{$input_width3}' id='{$params['class']}<%=num%>_title' value='<%=result?result['model']:''%>'/> </td>			
				<td class='textal'> <input type='text' name='{$params['name']}[<%=num%>][price]' {$input_maxlength2} style='{$input_width2}' id='{$params['class']}<%=num%>_title' value='<%=result?result['price']:''%>'/> </td>
				<td class='textal'> <input type='text' name='{$params['name']}[<%=num%>][price_old]' {$input_maxlength1} style='{$input_width1}' id='{$params['class']}<%=num%>_title' value='<%=result?result['price_old']:''%>'/> </td>
				<td class='textal'> <input type='text' name='{$params['name']}[<%=num%>][stock]' {$input_maxlength1} style='{$input_width1}' id='{$params['class']}<%=num%>_title' value='<%=result?result['stock']:''%>'/> </td>
				<td class='textac'> <img src='{$theme}/images/gg_icon2.png' class='reduce'/> </td>
			</tr>
		</script>
		<!--array_input E-->";
echo $html;